package com.controller.company;

import com.entity.Job;
import com.entity.User;
import com.service.AdminService;
import com.service.CompanyService;
import com.service.impl.AdminServiceimpl;
import com.service.impl.CompanyServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddJob")
public class AddJob extends HttpServlet {
//    AdminService adminService=new AdminServiceimpl();
    CompanyService companyService=new CompanyServiceimpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String companyId = req.getParameter("companyId");
        String jobName = req.getParameter("jobName");
        String jobType = req.getParameter("jobType");
        String salary= req.getParameter("salary");
        String jobAddress = req.getParameter("jobAddress");
        String jobDescription = req.getParameter("jobDescription");
        String low = req.getParameter("low");
        String high = req.getParameter("high");
        System.out.println("salary = " + salary);

        Job job = new Job();
        job.setCompanyId(companyId);
        job.setJobName(jobName);
        job.setJobType(jobType);
        job.setCompanyAddress(jobAddress);
        job.setJobDescription(jobDescription);
        job.setSalary(salary);
        job.setLow(Integer.parseInt(low));
        job.setHigh(Integer.parseInt(high));
        job.setState("未审核");
        job.setAudit_opinion("无");

        System.out.println("addjob = " + job);
//        int addi1 = adminService.AddCompany(company);
//        int addi1 = adminService.AddUser(user);
        int addi = companyService.AddJob(job);
        System.out.println("addjobi = " + addi);
        if(addi==1){
            resp.getWriter().write("success");
        }else{
            System.out.println(" error" );
            resp.getWriter().write("error");
        }
    }
}
